-----Purpose: Xu ly du lieu phan quyen khi them hoac xoa nhom nguoi dung
---------------------------------------------
-----Purpose: Bo sung them truong DataType
DROP PROCEDURE [dbo].[pr0093]
GO
CREATE PROCEDURE [dbo].[pr0093] @GroupID varchar(20), @Status char(1)
AS

SET NOCOUNT OFF

IF @Status='A' 
BEGIN
	INSERT INTO tb0075 (DivisionID,ModuleID,GroupID,DataID, DataType, Permission,CreateDate,CreateUserID)
	SELECT DISTINCT tb0076.DivisionID, tb0076.ModuleID, tb0070.GroupID, tb0076.DataID, DataType, 1 AS Expr1, GETDATE() AS Expr2, 'SABIADMIN' AS Expr3 
	FROM tb0076 CROSS JOIN tb0070
	WHERE   DivisionID + ModuleID + GroupID + DataID + DataType not in (SELECT DivisionID + ModuleID + GroupID + DataID + DataType FROM tb0075)
END

IF @Status='D' 

BEGIN
	DELETE FROM tb0075 WHERE GroupID=@GroupID	
END

SET NOCOUNT ON


GO